﻿using QD.Tools;
using QD_Clients.Code;
using QD_Clients.Code.DbContent;
using QD_Clients.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.ComboBox;

namespace QD_Clients.PM
{
    public partial class Reqs_QDDevPlat : BaseForm
    {
        private int PageSize = 500;
        private int TotalPage = 1;
        private PageState PageState = PageState.Browse;
        private string _QfCode = null;
        private string _LeaderCode = null;
        private string _LeaderName = null;
        private string _Status = null;
        private string _DeveloperCode = null;

        /// <summary>
        /// 需求编号
        /// </summary>
        private string _RSID
        {
            get
            {
                return this.latsid.Text.Trim();
            }
            set
            {
                this.latsid.Text = value;
            }
        }
        public Reqs_QDDevPlat()
        {
            InitializeComponent();
            this.gridList.InitGrid();
        }

        public void Reqs_QDDevPlat_Load(object sender, EventArgs e)
        {
            if (QDUserHelper.CurUser.IsManager)
            {
                toolStripButton1.Visible = true;
            }
            QDResources db = new QDResources();
            DataTable dt = db.Query("select QfCode,QfName,TesterCode,DeveloperCode,LeaderCode from QDDataBase");
            this.gridList.DataSource = dt;

            this.navigator.BindingSource = this.bindingSource;
            this.reqsList.DataSource = this.bindingSource;
            this.KeyPreview = true;
            this.KeyDown += BaseForm_KeyDown;

            this.reqsList.InitGrid(false, false, true);

            this.richTxtTools1.RichText = this.ReqtContext;

            DataTable dt_qdDataBase = db.Query("select * from QDDataBase");
            this.cmbQfCode.DisplayMember = "QfName";
            this.cmbQfCode.ValueMember = "QfCode";
            this.cmbQfCode.DataSource = dt_qdDataBase;
            this.cmbQfCode.SelectedIndex = -1;

            this.RTType.Items.AddRange(new string[] { "新程序", "追加功能" });
            this.RTType.SelectedIndex = -1;

            DataTable dt_qduser = db.Query("select * from QDUser order by Uid asc");
            this.SubmitToCode.DisplayMember = "UName";
            this.SubmitToCode.ValueMember = "Uid";
            this.SubmitToCode.DataSource = dt_qduser;

            DataTable dt_transfer = dt_qduser.Copy();
            this.TransferMan.DisplayMember = "UName";
            this.TransferMan.ValueMember = "Uid";
            this.TransferMan.DataSource = dt_transfer;
            this.TransferMan.SelectedIndex = -1;

            #region 初始化fileList
            //this.fileList.InitGrid(false, false, true);
            //this.fileList.ColumnHeadersVisible = false;
            //DataTable dt_fileList = new DataTable();
            //dt_fileList.Columns.Add("filename");
            //this.fileList.DataSource = dt_fileList;

            //DataGridViewButtonColumn listDelBtn = (DataGridViewButtonColumn)this.fileList.Columns["listDelBtn"];
            //listDelBtn.UseColumnTextForButtonValue = true;
            //listDelBtn.Text = "删除";

            //DataGridViewButtonColumn listOpenBtn = (DataGridViewButtonColumn)this.fileList.Columns["listOpenBtn"];
            //listOpenBtn.UseColumnTextForButtonValue = true;
            //listOpenBtn.Text = "打开";

            //DataGridViewButtonColumn listdownBtn = (DataGridViewButtonColumn)this.fileList.Columns["listdownBtn"];
            //listdownBtn.UseColumnTextForButtonValue = true;
            //listdownBtn.Text = "下载";

            //this.fileList.CellContentClick += fileList_CellContentClick;
            #endregion

            addClick();
            DataBind();

            gridList_CellContentDoubleClick(null, new DataGridViewCellEventArgs(0, 0));

        }
        void fileList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    DataGridView dv = (DataGridView)sender;
            //    if (dv.Columns[e.ColumnIndex].Name == "listDelBtn")
            //    {
            //        DialogResult result = MessageBox.Show("确认删除选择附件？", "提示", MessageBoxButtons.YesNo);
            //        if (result == DialogResult.Yes)
            //        {
            //            DataTable dt = (DataTable)this.fileList.DataSource;
            //            DataRow dr = dt.Rows[e.RowIndex];

            //            try
            //            {
            //                //FtpHelper ftp = new FtpHelper(ftpUri, QDUserHelper.LoginQdUser.FtpUid, QDUserHelper.LoginQdUser.FtpPwd);
            //                //ftp.delete(dr["fileName"].ToString());
            //            }
            //            catch { }

            //            dt.Rows.Remove(dr);

            //            updateDocList();
            //        }
            //    }
            //    else if (dv.Columns[e.ColumnIndex].Name == "listOpenBtn")
            //    {
            //        DataTable dt = (DataTable)this.fileList.DataSource;
            //        DataRow dr = dt.Rows[e.RowIndex];

            //        int lastIndex = dr["fileName"].ToString().LastIndexOf("\\");

            //        string localFile = dr["fileName"].ToString().Substring(lastIndex);
            //        string savePath = Path.Combine(Path.GetTempPath(), localFile);

            //        //FtpHelper ftp = new FtpHelper(ftpUri, QDUserHelper.LoginQdUser.FtpUid, QDUserHelper.LoginQdUser.FtpPwd);
            //        //ftp.get(dr["fileName"].ToString(), savePath);
            //        System.Diagnostics.Process.Start(savePath);
            //    }
            //    else if (dv.Columns[e.ColumnIndex].Name == "listdownBtn")
            //    {
            //        DataTable dt = (DataTable)this.fileList.DataSource;
            //        DataRow dr = dt.Rows[e.RowIndex];
            //        FolderBrowserDialog dialog = new FolderBrowserDialog();
            //        dialog.Description = "请选择下载位置";
            //        if (dialog.ShowDialog() == DialogResult.OK)
            //        {
            //            int lastIndex = dr["fileName"].ToString().LastIndexOf("\\");

            //            string localFile = dr["fileName"].ToString().Substring(lastIndex);
            //            string savePath = Path.Combine(dialog.SelectedPath, localFile);

            //            //FtpHelper ftp = new FtpHelper(ftpUri, QDUserHelper.LoginQdUser.FtpUid, QDUserHelper.LoginQdUser.FtpPwd);
            //            //ftp.get(dr["fileName"].ToString(), savePath);
            //            PromptHelper.Prompt("下载完成！");
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    PromptHelper.Prompt(ex.Message);
            //}
        }
        /// <summary>
        /// 是否编辑
        /// </summary>
        private void BeginEdit(bool isEdit)
        {
            this.ReqtName.ReadOnly =
                this.ReqtContext.ReadOnly = !isEdit;

        }

        private void ts_append_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(_QfCode))
            {
                addClick();
                this.cmbQfCode.SelectedValue = _QfCode;
                this.SubmitToCode.SelectedValue = _DeveloperCode;

                //DataTable dt = (DataTable)this.fileList.DataSource;
                //dt.Clear();
            }
            else
            {
                PromptHelper.Prompt("请选择产品后再操作！");
            }
        }

        private void addClick()
        {
            BeginEdit(true);
            this.cmbQfCode.SelectedIndex = -1;
            this.RTType.SelectedIndex = -1;
            this.SubmitToCode.SelectedIndex = -1;
            this.ReqtName.Clear();
            this.ReqtContext.Clear();
            this.lacreatorname.Text = "";
            this.lacreatedate.Text = "";
            this.ProcessDesc.Text = "";
            PageState = PageState.Append;

            this.SubmitToCode.Enabled = true;

            this._RSID = "";
            this.listLog.Items.Clear();

        }

        private void ts_modify_Click(object sender, EventArgs e)
        {
            BeginEdit(true);
            PageState = PageState.Modify;
        }

        private void ts_Update_Click(object sender, EventArgs e)
        {
            try
            {
                if (PageState == PageState.Browse)
                {
                    throw new Exception("当前需求未修改！");
                }
                string action = "";
                if (this.ReqtName.Text.Trim().Length == 0)
                {
                    throw new Exception("标题不能为空！");
                }
                else if (this.cmbQfCode.SelectedIndex == -1)
                {
                    throw new Exception("请选择产品！");
                }
                else if (this.SubmitToCode.SelectedIndex == -1)
                {
                    throw new Exception("请选择提交给谁！");
                }
                else if (this.SubmitToCode.SelectedValue.ToString() == QDUserHelper.CurUser.Uid)
                {
                    throw new Exception("不能提交给自己！");
                }
                else if (string.IsNullOrEmpty(this.RTType.Text))
                {
                    throw new Exception("请选择需求类型！");
                }

                QDResources db = new QDResources();
                var path = db.ExecuteScalar("select BTFilePath from Sys_Setting");
                if (path == null)
                {
                    throw new Exception("请设置存储路径！");
                }
                PM_Reqs mst = null;
                if (!string.IsNullOrEmpty(this._RSID))
                {
                    mst = db.PM_Reqs.FirstOrDefault(p => p.RSID == this._RSID);
                    if (mst == null)
                    {
                        throw new Exception("需求[" + this._RSID + "]不存在或已经被删除！");
                    }
                    action = "修改";
                }
                else
                {
                    mst = new PM_Reqs();
                    mst.RSID = PM_ReqsHelper.GetNewId();
                    mst.QfCode = this.cmbQfCode.SelectedValue.ToString();
                    mst.CreatorCode = QDUserHelper.CurUser.Uid;
                    mst.CreatorName = QDUserHelper.CurUser.UName;
                    mst.CreateDate = DateTime.Now;
                    mst.SubmitToCode = this.SubmitToCode.SelectedValue.ToString();
                    mst.SubmitToName = this.SubmitToCode.Text;
                    mst.NextProcessorCode = this.SubmitToCode.SelectedValue.ToString();
                    mst.NextProcessorName = this.SubmitToCode.Text;
                    mst.Status = TestStatus.noSubmit.ToString();
                    db.PM_Reqs.Add(mst);
                    action = "新增";
                }
                mst.ReqtName = this.ReqtName.Text.Trim();
                mst.RTType = this.RTType.Text;
                //mst.DocList = GetDocList();
                this._RSID = mst.RSID;
                byte[] b = RtfHelper.GetRichTextBoxData(this.ReqtContext);
                mst.FilePath = RtfHelper.UploadFile(b, path.ToString());



                db.SaveChanges();
                BeginEdit(false);
                PromptHelper.Prompt("保存成功！");

                PM_ReqsHelper.AddBugProcessList(db, mst.RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), action, "", "");
                db.SaveChanges();
                InitUIData(mst.RSID);
                DataBind();
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void ts_delete_Click(object sender, EventArgs e)
        {
            try
            {
                QDResources dbConfig = new QDResources();
                PM_Reqs mst = IsCurrentExists(dbConfig);
                if (mst != null)
                {
                    if (PromptHelper.PromptOkCancel("确认删除当前需求？") == DialogResult.OK)
                    {
                        if (mst.Status != TestStatus.noSubmit.ToString())
                        {
                            throw new Exception("当前需求不处理于未提交状态，不能删除！");
                        }
                        else
                        {
                            dbConfig.PM_Reqs.Remove(mst);

                            //删除日志
                            var query = dbConfig.PM_ReqsProcessList.Where(p => p.RSID == mst.RSID);
                            foreach (var q in query)
                            {
                                dbConfig.PM_ReqsProcessList.Remove(q);
                            }
                            dbConfig.SaveChanges();
                            PromptHelper.Prompt("删除成功！");
                            DataBind();
                            ts_append_Click(sender, e);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.curPageIndex.Text != "1")
            {
                this.curPageIndex.Text = "1";
            }
            else
            {
                DataBind();
            }
        }

        private void navigator_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            try
            {
                int pageIndex = GetCurPageIndex();

                switch (e.ClickedItem.Text)
                {
                    case "上一页":
                        {
                            if (pageIndex == 1)
                            {
                                PromptHelper.Prompt("已经是第一页了！");
                            }
                            else
                            {
                                this.curPageIndex.Text = (--pageIndex).ToString();
                            }

                            break;
                        }
                    case "下一页":
                        {
                            if (pageIndex == TotalPage)
                            {
                                PromptHelper.Prompt("已经是最后一页了！");
                            }
                            else
                            {
                                this.curPageIndex.Text = (++pageIndex).ToString();
                            }

                            break;
                        }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private int GetCurPageIndex()
        {
            int pageIndex = 1;
            string txtCurPageIndex = this.curPageIndex.Text.Trim();
            if (string.IsNullOrEmpty(txtCurPageIndex))
            {
                throw new Exception("请输入正确的页码！");
            }
            else if (!int.TryParse(txtCurPageIndex, out pageIndex))
            {
                throw new Exception("请输入正确的页码！");
            }
            return pageIndex;
        }

        private void DataBind()
        {
            try
            {
                if (!string.IsNullOrEmpty(this.curPageIndex.Text.Trim()))
                {
                    int pageIndex = GetCurPageIndex();
                    string filter = getFilter();
                    QDResources db = new QDResources();
                    string sql1 = "select top 100  percent  ROW_NUMBER() over(order by RSID asc) as AID,* from PM_Reqs where QfCode='" + _QfCode + "' and " + filter + " order by LastProcessDate desc";
                    string sql2 = "";
                    if (QDUserHelper.CurUser.IsManager)
                    {
                        sql2 = string.Format("select  top {0} RSID,'['+SubmitToName+'] '+ReqtName as ReqtName,CreateDate,CreatorCode from ({1}) t where AID>{2} order by AID asc", PageSize, sql1, ((pageIndex - 1) * PageSize).ToString());
                    }
                    else
                    {
                        sql2 = string.Format("select  top {0} RSID,'['+SubmitToName+'] '+ReqtName as ReqtName,CreateDate,CreatorCode from ({1}) t where AID>{2} order by AID asc", PageSize, sql1, ((pageIndex - 1) * PageSize).ToString());
                    }
                    DataTable dt = db.Query(sql2);
                    this.bindingSource.DataSource = dt;



                    object qtyNoSubmit = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpNoSubmit"));
                    this.tpNoSubmit.Text = "未提交(" + qtyNoSubmit.ToString() + ")";

                    //object qtySubmit = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpSubmit"));
                    //this.tpSubmit.Text = "已提交(" + qtySubmit.ToString() + ")";

                    object qtToAudit = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpToAudit"));
                    this.tpToAudit.Text = "待审核(" + qtToAudit.ToString() + ")";

                    //object qtyReviewed = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpReviewed"));
                    //this.tpReviewed.Text = "已审核(" + qtyReviewed.ToString() + ")";

                    object qtReviewFailed = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpReviewFailed"));
                    this.tpReviewFailed.Text = "审核未通过(" + qtReviewFailed.ToString() + ")";

                    object qtywaitProcess = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpWaitProcess"));
                    this.tpWaitProcess.Text = "待处理(" + qtywaitProcess.ToString() + ")";

                    //object qtyProcessed = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpProcessed"));
                    //this.tpProcessed.Text = "已处理(" + qtyProcessed.ToString() + ")";

                    object qtyConfirm = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpConfirm"));
                    this.tpConfirm.Text = "待确认(" + qtyConfirm.ToString() + ")";

                    object qtyFinish = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpFinish"));
                    this.tpFinish.Text = "已完成(" + qtyFinish.ToString() + ")";

                    object qtyRecall = db.ExecuteScalar("select count(*) from PM_Reqs where QfCode='" + _QfCode + "' and " + getFilter("tpRecall"));
                    this.tpRecall.Text = "已撤消(" + qtyRecall.ToString() + ")";

                    switch (this.tabControl1.SelectedTab.Name)
                    {
                        case "tpNoSubmit":
                            this.totalCount.Text = qtyNoSubmit.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtyNoSubmit) * 1.0 / PageSize)));
                            break;
                        //case "tpSubmit":
                        //    this.totalCount.Text = qtySubmit.ToString();
                        //    TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtySubmit) * 1.0 / PageSize)));
                        //    break;
                        case "tpToAudit":
                            this.totalCount.Text = qtToAudit.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtToAudit) * 1.0 / PageSize)));
                            break;
                        //case "tpReviewed":
                        //    this.totalCount.Text = qtyReviewed.ToString();
                        //    TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtyReviewed) * 1.0 / PageSize)));
                        //    break;
                        case "tpReviewFailed":
                            this.totalCount.Text = qtReviewFailed.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtReviewFailed) * 1.0 / PageSize)));
                            break;
                        case "tpWaitProcess":
                            this.totalCount.Text = qtywaitProcess.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtywaitProcess) * 1.0 / PageSize)));
                            break;
                        //case "tpProcessed":
                        //    this.totalCount.Text = qtyProcessed.ToString();
                        //    TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtyProcessed) * 1.0 / PageSize)));
                        //    break;
                        case "tpConfirm":
                            this.totalCount.Text = qtyConfirm.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtyConfirm) * 1.0 / PageSize)));
                            break;
                        case "tpFinish":
                            this.totalCount.Text = qtyFinish.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtyFinish) * 1.0 / PageSize)));
                            break;
                        case "tpRecall":
                            this.totalCount.Text = qtyRecall.ToString();
                            TotalPage = Convert.ToInt32(Math.Ceiling((decimal)(Convert.ToInt32(qtyRecall) * 1.0 / PageSize)));
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private string getFilter()
        {
            string filter = getFilter(this.tabControl1.SelectedTab.Name);

            string _keyTxt = this.txtKey.Text.Trim();
            if (!string.IsNullOrEmpty(_keyTxt))
            {
                if (!string.IsNullOrEmpty(filter))
                {
                    filter += " and ";
                }
                filter += string.Format("(ReqtName like '%{0}%' or RSID like '%{0}%')", _keyTxt);
            }

            string _filter;
            if (!string.IsNullOrEmpty(filter))
            {
                _filter = "(" + filter + ")";
            }
            else
            {
                _filter = filter;
            }

            return _filter;
        }

        private string getFilter(string bug_status)
        {
            string filter = "";
            if (QDUserHelper.CurUser.IsManager)
            {
                switch (bug_status)
                {

                    case "tpNoSubmit": //未提交
                        {
                            filter = string.Format("Status='{0}'", TestStatus.noSubmit.ToString());
                            break;
                        }
                    //case "tpSubmit": //已提交
                    //    {
                    //        filter = string.Format("Status='{0}'", TestStatus.toAudit.ToString());
                    //        break;
                    //    }
                    case "tpToAudit": //待审核
                        {
                            filter = string.Format("Status='{0}'", TestStatus.toAudit.ToString());
                            break;
                        }
                    //case "tpReviewed": //已审核
                    //    {
                    //        filter = string.Format("Status='{0}'", TestStatus.waitingProcess.ToString());
                    //        break;
                    //    }
                    case "tpReviewFailed": //审核未通过
                        {
                            filter = string.Format("Status='{0}'", TestStatus.reviewFailed.ToString());
                            break;
                        }
                    case "tpWaitProcess": //待处理
                        {
                            filter = string.Format("Status='{0}'", TestStatus.waitingProcess.ToString());
                            break;
                        }
                    //case "tpProcessed": //已处理
                    //    {
                    //        filter = string.Format("Status='{0}'", TestStatus.waitingConfirm.ToString());
                    //        break;
                    //    }
                    case "tpConfirm": //待确认
                        {
                            filter = string.Format("Status='{0}'", TestStatus.waitingConfirm.ToString());
                            break;
                        }
                    case "tpFinish": //已完成
                        {
                            filter = string.Format("Status='{0}'", TestStatus.finish.ToString());
                            break;
                        }
                    case "tpRecall": //已撤消
                        {
                            filter = string.Format("Status='{0}'", TestStatus.recall.ToString());
                            break;
                        }
                }
            }
            else
            {
                switch (bug_status)
                {

                    case "tpNoSubmit": //未提交
                        {
                            filter = string.Format("CreatorCode='{0}' and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.noSubmit.ToString());
                            break;
                        }
                    //case "tpSubmit": //已提交
                    //    {
                    //        filter = string.Format("CreatorCode='{0}' and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.toAudit.ToString());
                    //        break;
                    //    }
                    case "tpToAudit": //待审核
                        {
                            filter = string.Format("(CreatorCode='{0}' or NextProcessorCode='{0}') and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.toAudit.ToString());
                            break;
                        }
                    //case "tpReviewed": //已审核
                    //    {
                    //        filter = string.Format("CreatorCode='{0}' and Status='{0}'", QDUserHelper.CurUser.Uid, TestStatus.waitingProcess.ToString());
                    //        break;
                    //    }
                    case "tpReviewFailed": //审核未通过
                        {
                            filter = string.Format("CreatorCode='{0}' and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.reviewFailed.ToString());
                            break;
                        }
                    case "tpWaitProcess": //待处理
                        {
                            filter = string.Format("(CreatorCode='{0}' or NextProcessorCode='{0}')  and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.waitingProcess.ToString());
                            break;
                        }
                    //case "tpProcessed": //已处理
                    //    {
                    //        filter = string.Format("CreatorCode='{0}' and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.waitingConfirm.ToString());
                    //        break;
                    //    }
                    case "tpConfirm": //待确认
                        {
                            filter = string.Format("(CreatorCode='{0}' or NextProcessorCode='{0}') and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.waitingConfirm.ToString());
                            break;
                        }
                    case "tpFinish": //已处理
                        {
                            filter = string.Format("CreatorCode='{0}' and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.finish.ToString());
                            break;
                        }
                    case "tpRecall": //已撤消
                        {
                            filter = string.Format("CreatorCode='{0}' and Status='{1}'", QDUserHelper.CurUser.Uid, TestStatus.recall.ToString());
                            break;
                        }
                }
            }

            return filter;
        }

        private void ts_Reload_Click(object sender, EventArgs e)
        {
            this.curPageIndex.Text = "1";
            DataBind();
        }

        void BaseForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Control && e.KeyCode == Keys.A)
            {
                ts_append_Click(sender, e);
            }
            else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D)
            {
                ts_delete_Click(sender, e);
            }
            else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.E)
            {
                ts_modify_Click(sender, e);
            }
            else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.S)
            {
                ts_Update_Click(sender, e);
            }
        }

        private void reqsList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && e.ColumnIndex > -1)
            {
                string _rsId = this.reqsList.Rows[e.RowIndex].Cells["listRSID"].Value.ToString();
                string _creatorCode = this.reqsList.Rows[e.RowIndex].Cells["CreatorCode"].Value.ToString();
                InitUIData(_rsId);
                var submit = this.SubmitToCode.SelectedValue.ToString();
                if (QDUserHelper.CurUser.Uid == submit /*&& _creatorCode!=submit*/ && _Status == "waitingProcess")
                {
                    this.btnDispose.Visible = true;
                    this.btnSubmit.Visible = false;
                    this.btnApproval.Visible = false;
                    this.btnFinish.Visible = false;
                    this.btnreCall.Visible = false;
                    this.btnTransfer.Visible = false;
                    this.TransferMan.Visible = false;
                }
                else
                {
                    this.btnDispose.Visible = false;
                    this.btnSubmit.Visible = true;
                    this.btnApproval.Visible = true;
                    this.btnFinish.Visible = true;
                    this.btnreCall.Visible = true;
                    this.btnTransfer.Visible = true;
                    this.TransferMan.Visible = true;
                }
            }
        }

        protected void InitUIData(string rsid)
        {
            try
            {
                PageState = PageState.Browse;
                this.SubmitToCode.Enabled = false;

                QDResources db = new QDResources();
                PM_Reqs mst = db.PM_Reqs.FirstOrDefault(p => p.RSID == rsid);

                if (mst != null)
                {
                    this._RSID = rsid;
                    this.ReqtName.Text = mst.ReqtName;
                    if (!string.IsNullOrEmpty(mst.FilePath))
                    {
                        byte[] b = RtfHelper.DownloadFiles(mst.FilePath);
                        RtfHelper.LoadRichTextBoxData(this.ReqtContext, b);
                    }
                    else
                    {
                        this.ReqtContext.Clear();
                    }
                    _Status = mst.Status;
                    if (mst.Status == "reviewFailed")
                    {
                        this.pictureBox1.Image = global::QD_Clients.Properties.Resources.审核未通过;
                    }
                    else if (mst.Status == "waitingProcess" || mst.Status == "waitingConfirm")
                    {
                        this.pictureBox1.Image = global::QD_Clients.Properties.Resources.已审核;
                    }
                    //else if (mst.Status == "waitingConfirm")
                    //{
                    //    this.pictureBox1.Image = global::QD_Clients.Properties.Resources.待确认;
                    //}
                    //else if (mst.Status == "waitingProcess")
                    //{
                    //    this.pictureBox1.Image = global::QD_Clients.Properties.Resources.待处理;
                    //}
                    else if (mst.Status == "finish")
                    {
                        this.pictureBox1.Image = global::QD_Clients.Properties.Resources.已完成;
                    }
                    else if (mst.Status == "recall")
                    {
                        this.pictureBox1.Image = global::QD_Clients.Properties.Resources.已撤销;
                    }
                    else
                    {
                        this.pictureBox1.Image = global::QD_Clients.Properties.Resources.未审核;
                    }
                    this.RTType.SelectedItem = mst.RTType;
                    this.cmbQfCode.SelectedValue = mst.QfCode;
                    this.SubmitToCode.SelectedValue = mst.SubmitToCode;
                    this.lacreatorname.Text = mst.CreatorName;
                    this.lacreatedate.Text = mst.CreateDate.ToString("yyyy-MM-dd HH:mm:ss");
                    //BindDocList(mst.DocList);
                    BeginEdit(false);
                    PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);

                    this.ProcessDesc.Text = "";
                }
                else
                {
                    throw new Exception("需求[" + this._RSID + "]不存在或已经被删除！");
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private PM_Reqs IsCurrentExists(QDResources dbConfig)
        {
            PM_Reqs mst = null;
            if (string.IsNullOrEmpty(this._RSID))
            {
                PromptHelper.Prompt("未加载任何需求信息！");
            }
            else
            {
                mst = dbConfig.PM_Reqs.FirstOrDefault(p => p.RSID == _RSID);

                if (mst == null)
                {
                    PromptHelper.Prompt("需求 [" + this._RSID + "] 未保存或已经被删除！");
                }
            }

            return mst;
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (PageState != PageState.Browse)
                {
                    throw new Exception("当前需求未保存！");
                }
                QDResources dbConfig = new QDResources();
                PM_Reqs mst = IsCurrentExists(dbConfig);
                if (mst != null)
                {
                    if (PromptHelper.PromptOkCancel("确认提交当前需求？") == DialogResult.OK)
                    {
                        if (!(mst.Status == TestStatus.noSubmit.ToString() || mst.Status == TestStatus.waitingConfirm.ToString()))
                        {
                            throw new Exception("当前需求开发人员未处理，不可以提交！");
                        }
                        if (mst.Status == TestStatus.finish.ToString())
                        {
                            throw new Exception("当前需求已完成！");
                        }
                        else if (mst.Status == TestStatus.recall.ToString())
                        {
                            throw new Exception("当前需求已撤消！");
                        }

                        mst.LastProcessDate = DateTime.Now;
                        mst.NextProcessorCode = _LeaderCode;
                        DataTable dt = (DataTable)this.SubmitToCode.DataSource;
                        foreach (DataRow item in dt.Rows)
                        {
                            if (item["Uid"].ToString() == _LeaderCode)
                            {
                                _LeaderName = item["UName"].ToString();
                                break;
                            }
                        }
                        mst.NextProcessorName = _LeaderName;
                        //mst.Status = TestStatus.waitingProcess.ToString();
                        mst.Status = TestStatus.toAudit.ToString();
                        PM_ReqsHelper.AddBugProcessList(dbConfig, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "提交", mst.NextProcessorCode, mst.NextProcessorName);
                        dbConfig.SaveChanges();
                        PromptHelper.Prompt("提交成功！");
                        PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void btnFinish_Click(object sender, EventArgs e)
        {
            try
            {
                if (PageState != PageState.Browse)
                {
                    throw new Exception("当前需求未保存！");
                }
                QDResources dbConfig = new QDResources();
                PM_Reqs mst = IsCurrentExists(dbConfig);
                if (mst != null)
                {
                    if (PromptHelper.PromptOkCancel("确认完成当前需求？") == DialogResult.OK)
                    {
                        if (mst.Status == TestStatus.finish.ToString())
                        {
                            throw new Exception("当前需求已完成！");
                        }
                        else if (mst.Status == TestStatus.recall.ToString())
                        {
                            throw new Exception("当前需求已撤消！");
                        }
                        else if (!(mst.Status == TestStatus.waitingConfirm.ToString()))
                        {
                            throw new Exception("当前需求开发人员未处理，不可以完成！");
                        }
                        else if (mst.Status == TestStatus.reviewFailed.ToString())
                        {
                            throw new Exception("当前需求审核未通过！");
                        }
                        mst.LastProcessDate = DateTime.Now;
                        mst.NextProcessorCode = "";
                        mst.NextProcessorName = "";
                        mst.Status = TestStatus.finish.ToString();

                        PM_ReqsHelper.AddBugProcessList(dbConfig, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "完成", mst.NextProcessorCode, mst.NextProcessorName);
                        dbConfig.SaveChanges();
                        PromptHelper.Prompt("完成成功！");
                        PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void btnreCall_Click(object sender, EventArgs e)
        {
            try
            {
                if (PageState != PageState.Browse)
                {
                    throw new Exception("当前需求未保存！");
                }
                QDResources dbConfig = new QDResources();
                PM_Reqs mst = IsCurrentExists(dbConfig);
                if (mst != null)
                {
                    if (PromptHelper.PromptOkCancel("确认撤消当前需求？") == DialogResult.OK)
                    {
                        if (mst.Status == TestStatus.finish.ToString())
                        {
                            throw new Exception("当前需求已完成！");
                        }
                        else if (mst.Status == TestStatus.recall.ToString())
                        {
                            throw new Exception("当前需求已撤消！");
                        }

                        mst.LastProcessDate = DateTime.Now;
                        mst.NextProcessorCode = "";
                        mst.NextProcessorName = "";
                        mst.Status = TestStatus.recall.ToString();

                        PM_ReqsHelper.AddBugProcessList(dbConfig, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "撤消", mst.NextProcessorCode, mst.NextProcessorName);
                        dbConfig.SaveChanges();
                        PromptHelper.Prompt("撤消成功！");
                        PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void btnTransfer_Click(object sender, EventArgs e)
        {
            try
            {
                if (PageState != PageState.Browse)
                {
                    throw new Exception("当前需求未保存！");
                }
                QDResources dbConfig = new QDResources();
                PM_Reqs mst = IsCurrentExists(dbConfig);
                if (mst != null)
                {
                    if (PromptHelper.PromptOkCancel("确认转移当前需求？") == DialogResult.OK)
                    {
                        if (mst.Status == TestStatus.finish.ToString())
                        {
                            throw new Exception("当前需求已完成！");
                        }
                        else if (mst.Status == TestStatus.recall.ToString())
                        {
                            throw new Exception("当前需求已撤消！");
                        }
                        else if (!(mst.Status == TestStatus.waitingConfirm.ToString()))
                        {
                            throw new Exception("当前需求开发人员未处理，不可以转移");
                        }

                        if (this.TransferMan.SelectedIndex == -1)
                        {
                            throw new Exception("请选择转移接收人！");
                        }

                        mst.LastProcessDate = DateTime.Now;
                        mst.SubmitToCode = this.TransferMan.SelectedValue.ToString();
                        mst.SubmitToName = this.TransferMan.Text;
                        mst.NextProcessorCode = this.TransferMan.SelectedValue.ToString();
                        mst.NextProcessorName = this.TransferMan.Text;
                        mst.Status = TestStatus.waitingProcess.ToString();

                        PM_ReqsHelper.AddBugProcessList(dbConfig, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "转移", mst.NextProcessorCode, mst.NextProcessorName);
                        dbConfig.SaveChanges();
                        PromptHelper.Prompt("转移成功！");
                        PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void curPageIndex_TextChanged(object sender, EventArgs e)
        {
            DataBind();
        }

        private void t_monitoring_Tick(object sender, EventArgs e)
        {
            this.curPageIndex.Text = "1";
            DataBind();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            DataBind();
        }

        private void txtKey_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                toolStripButton6_Click(sender, e);
            }
        }

        private void ts_next_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_RSID))
            {
                PromptHelper.Prompt("未加载任何需求信息！");
            }
            else
            {
                QDResources db = new QDResources();
                string filter = getFilter();
                string sql = string.Format("select top 1 RSID from PM_Reqs where RSID>'{0}' and {1} order by RSID asc", _RSID, filter);
                object _tsId = db.ExecuteScalar(sql);
                if (_tsId == null || _tsId.ToString().Length == 0)
                {
                    PromptHelper.Prompt("已经是最后一条数据了！");
                }
                else
                {
                    InitUIData(_tsId.ToString());
                }
            }
        }

        private void ts_prev_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_RSID))
            {
                PromptHelper.Prompt("未加载任何需求信息！");
            }
            else
            {
                QDResources db = new QDResources();
                string filter = getFilter();
                string sql = string.Format("select top 1 RSID from PM_Reqs where RSID<'{0}' and {1} order by RSID desc", _RSID, filter);
                object _tsId = db.ExecuteScalar(sql);
                if (_tsId == null || _tsId.ToString().Length == 0)
                {
                    PromptHelper.Prompt("已经是第一条数据了！");
                }
                else
                {
                    InitUIData(_tsId.ToString());
                }
            }
        }

        private void gridList_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && e.ColumnIndex > -1)
            {
                if (this.gridList.Rows.Count > 0)
                {
                    _QfCode = this.gridList.Rows[e.RowIndex].Cells["QfCode"].Value.ToString();
                    _DeveloperCode = this.gridList.Rows[e.RowIndex].Cells["DeveloperCode"].Value.ToString();
                    _LeaderCode = this.gridList.Rows[e.RowIndex].Cells["LeaderCode"].Value.ToString();
                    addClick();
                    DataBind();
                }
            }
        }
        private void 复制单元格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.gridList.CopyFirstSelectedCellValue();
        }

        private void 复制所有选中单元格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.gridList.CopySelectedCellsValue();
        }
        Form nf;
        TextBox tb;
        string _strPath = "";
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            QDResources db = new QDResources();
            var path = db.ExecuteScalar("select BTFilePath from Sys_Setting");
            if (path != null)
            {
                _strPath = path.ToString();
            }
            nf = new Form();
            int _w = 410;
            int _h = 150;
            nf.Width = _w;
            nf.Height = _h;
            //添加textbox
            tb = new TextBox();
            tb.Name = "txt";
            //tb.Multiline = true;
            tb.Top = 50;
            tb.Left = 5;
            tb.Width = 300;
            tb.Text = _strPath;
            nf.Controls.Add(tb);
            //添加保存按钮
            Button but = new Button();
            but.Top = 50;
            but.Left = 310;
            but.Name = "btnSave";
            but.Text = "保存";
            but.Click += But_Click;
            nf.Controls.Add(but);
            nf.StartPosition = FormStartPosition.CenterScreen;
            nf.MaximizeBox = false;
            nf.MinimizeBox = false;
            nf.ShowIcon = false;
            nf.Text = "保存路径";
            nf.ShowDialog();

        }

        private void But_Click(object sender, EventArgs e)
        {
            var path = tb.Text;
            if (_strPath == "")
            {
                QDResources db = new QDResources();
                db.ExecuteNonQuery(string.Format("insert into Sys_Setting (BTFilePath) VALUES ('{0}')", path));
            }
            else
            {
                QDResources db = new QDResources();
                db.ExecuteNonQuery(string.Format("UPDATE Sys_Setting SET BTFilePath = '{0}'", path));
            }
            MessageBox.Show("保存成功！");
            nf.Close();
        }

        private void btnDispose_Click(object sender, EventArgs e)
        {
            try
            {
                if (PageState != PageState.Browse)
                {
                    throw new Exception("当前需求未保存！");
                }
                QDResources dbConfig = new QDResources();
                PM_Reqs mst = IsCurrentExists(dbConfig);
                if (mst != null)
                {
                    if (PromptHelper.PromptOkCancel("确认处理当前需求？") == DialogResult.OK)
                    {
                        if (mst.Status == TestStatus.toAudit.ToString())
                        {
                            throw new Exception("当前需求未审核！");
                        }
                        else if (mst.Status == TestStatus.reviewFailed.ToString())
                        {
                            throw new Exception("当前需求审核未通过！");
                        }
                        else if (mst.Status == TestStatus.finish.ToString())
                        {
                            throw new Exception("当前需求已完成！");
                        }
                        else if (mst.Status == TestStatus.recall.ToString())
                        {
                            throw new Exception("当前需求已撤消！");
                        }
                        else if (mst.Status != TestStatus.waitingProcess.ToString())
                        {
                            throw new Exception("当前需求测试未提交，不可以处理！");
                        }
                        else if (mst.NextProcessorCode != QDUserHelper.CurUser.Uid)
                        {
                            throw new Exception("当前需求的处理人为[" + mst.NextProcessorName + "]！");
                        }

                        mst.LastProcessDate = DateTime.Now;
                        mst.NextProcessorCode = mst.CreatorCode;
                        mst.NextProcessorName = mst.CreatorName;
                        mst.Status = TestStatus.waitingConfirm.ToString();

                        PM_ReqsHelper.AddBugProcessList(dbConfig, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "处理", mst.NextProcessorCode, mst.NextProcessorName);
                        dbConfig.SaveChanges();
                        PromptHelper.Prompt("提交成功！");
                        this.ProcessDesc.Clear();
                        PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);
                        this.btnDispose.Visible = false;
                        this.btnSubmit.Visible = true;
                        this.btnApproval.Visible = true;
                        this.btnFinish.Visible = true;
                        this.btnreCall.Visible = true;
                        this.btnTransfer.Visible = true;
                        this.TransferMan.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                PromptHelper.Prompt(ex);
            }
        }

        private void btnApproval_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_RSID))
            {
                PromptHelper.Prompt("未加载任何需求信息！");
            }
            else
            {
                QDResources db = new QDResources();
                PM_Reqs mst = db.PM_Reqs.First(p => p.RSID == this._RSID);
                if (mst != null)
                {
                    if (mst.Status != TestStatus.toAudit.ToString())
                    {
                        PromptHelper.Prompt("当前需求不是待审核状态！");
                        return;
                    }
                    else if (!QDUserHelper.CurUser.IsManager || QDUserHelper.CurUser.Uid != _LeaderCode)
                    {
                        PromptHelper.Prompt("不是项目负责人或管理员不能审核！");
                        return;
                    }
                    DialogResult dr = MessageBox.Show("是否审核通过", "审核", MessageBoxButtons.YesNoCancel);
                    if (dr == DialogResult.Yes)
                    {
                        mst.Status = TestStatus.waitingProcess.ToString();
                        mst.NextProcessorCode = this.SubmitToCode.SelectedValue.ToString();
                        DataTable dt = (DataTable)this.SubmitToCode.DataSource;
                        string nextName = "";
                        foreach (DataRow item in dt.Rows)
                        {
                            if (item["Uid"].ToString() == mst.NextProcessorCode)
                            {
                                nextName = item["UName"].ToString();
                                break;
                            }
                        }
                        mst.NextProcessorName = nextName;
                        PM_ReqsHelper.AddBugProcessList(db, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "审核通过", mst.NextProcessorCode, mst.NextProcessorName);
                    }
                    else if (dr == DialogResult.No)
                    {
                        string value = this.ProcessDesc.Text.Trim();
                        if (string.IsNullOrEmpty(value))
                        {
                            PromptHelper.Prompt("当审核不通过请填写原因！");
                            return;
                        }
                        else
                        {
                            mst.Status = TestStatus.reviewFailed.ToString();
                            mst.NextProcessorCode = mst.CreatorCode;
                            DataTable dt = (DataTable)this.SubmitToCode.DataSource;
                            string nextName = "";
                            foreach (DataRow item in dt.Rows)
                            {
                                if (item["Uid"].ToString() == mst.NextProcessorCode)
                                {
                                    nextName = item["UName"].ToString();
                                    break;
                                }
                            }
                            mst.NextProcessorName = nextName;
                            PM_ReqsHelper.AddBugProcessList(db, this._RSID, QDUserHelper.CurUser.Uid, QDUserHelper.CurUser.UName, this.ProcessDesc.Text.Trim(), "审核不通过", mst.NextProcessorCode, mst.NextProcessorName);
                        }
                    }
                    else
                    {
                        return;
                    }

                    db.SaveChanges();
                    PromptHelper.Prompt("操作成功！");
                    this.ProcessDesc.Clear();
                    PM_ReqsHelper.BindProcessList(this.listLog, this._RSID);
                }

            }
        }

        //private void gridList_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        //{
        //    e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        //}
        //private void pl_autoup_DragDrop(object sender, DragEventArgs e)
        //{
        //    try
        //    {
        //        string filename = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();

        //        uploadFile(filename);
        //    }
        //    catch (Exception ex)
        //    {
        //        PromptHelper.Prompt(ex.Message);
        //    }
        //}
        //private void pl_autoup_MouseDoubleClick(object sender, MouseEventArgs e)
        //{
        //    try
        //    {
        //        OpenFileDialog dialog = new OpenFileDialog();
        //        dialog.Multiselect = true;
        //        if (dialog.ShowDialog() == DialogResult.OK)
        //        {
        //            string[] fileNames = dialog.FileNames;
        //            foreach (string fname in fileNames)
        //            {
        //                uploadFile(fname);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        PromptHelper.Prompt(ex.Message);
        //    }
        //}
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="filename"></param>
        //private void uploadFile(string filename)
        //{
        //    QDResources db = new QDResources();
        //    var path = db.ExecuteScalar("select BTFilePath from Sys_Setting");
        //    if (path == null)
        //    {
        //        throw new Exception("请设置存储路径！");
        //    }
        //    //服务器上传地址
        //    string url = WebClientHelper.ServerUri;
        //    //年月文件夹
        //    string UploadFile = "/" + DateTime.Now.ToString("yyyyMM") + "/";
        //    //服务器文件地址
        //    string serverFile = path + UploadFile;
        //    //把本地文件上传到服务器
        //    RtfHelper.UpLoadFile(filename, serverFile, url);
        //    string _ftpPath = serverFile.Split(':')[1] + filename;

        //    DataTable dt = (DataTable)this.fileList.DataSource;
        //    dt.Rows.Add(_ftpPath);

        //    updateDocList();

        //}
        /// <summary>
        /// 求需求的文档
        /// </summary>
        /// <returns></returns>
        //private string GetDocList()
        //{
        //    DataTable dt = (DataTable)this.fileList.DataSource;
        //    string docList = "";
        //    foreach (DataRow dr in dt.Rows)
        //    {
        //        if (docList != "")
        //        {
        //            docList += ";";
        //        }
        //        docList += dr["fileName"].ToString();
        //    }

        //    return docList;
        //}

        /// <summary>
        /// 绑定需求文档列表
        /// </summary>
        /// <param name="doclist"></param>
        //private void BindDocList(string doclist)
        //{
        //    DataTable dt = (DataTable)this.fileList.DataSource;
        //    dt.Clear();

        //    if (!string.IsNullOrEmpty(doclist))
        //    {
        //        string[] list = doclist.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
        //        foreach (string s in list)
        //        {
        //            dt.Rows.Add(s);
        //        }
        //    }
        //}
        /// <summary>
        /// 保存PM_Reqs的DocList字段，用户点击删除附件后，如果没有重新保存当前需求，则会造成文件不存在，所以更新附件后要及时更新
        /// </summary>
        //private void updateDocList()
        //{
        //    QDResources dbConfig = new QDResources();
        //    PM_Reqs mst = dbConfig.PM_Reqs.FirstOrDefault(p => p.RSID == _RSID);
        //    if (mst != null)
        //    {
        //        string docList = GetDocList();
        //        string sql = string.Format("update PM_Reqs set DocList='{0}' where RSID='{1}'", docList, mst.RSID);
        //        dbConfig.ExecuteNonQuery(sql);
        //    }
        //}
    }
}
